<?php
include("utils.php");
if($_SESSION['siteuserId']=="")
{
	header("location:index.php");
}

if($_POST['mode']=="save_landing_page")
{
	save_landing_page();
}
else
{
	main_content("main();");
}

function main()
{
$sql="select * from adspace_landing_page where landingId='".$_REQUEST['id']."' ";
$query=mysql_query($sql);
$rec=mysql_fetch_array($query);
?><script language=JavaScript src="JavaScripts/picker.js"></script><script language="JavaScript">

function changeValue(strValue, strLength, countId) {
//alert(countId);
        if (strValue.length <= strLength) {
            if (strValue != null) {

				document.getElementById("description_final").innerHTML=strValue;
                document.getElementById(countId).innerHTML = (strLength - strValue.length);
                if (countId == 'tagsCount' && (strValue.indexOf('"') >= 0 || strValue.indexOf("'") >= 0 || strValue.indexOf("|") >= 0 || strValue.indexOf("\\") >= 0)) {
                    var message = "Invalid tag, please re-enter tags without |, \', \", \\ in it.";
                    alert(message);
            }
            }
        }
        else {
            document.getElementById(countId).innerHTML = "<span style=\"color:red\">Too many characters for description!</span>";
        }
    }

function changeValue1(strValue, strLength, countId) {
document.getElementById("site_title_show").innerHTML=strValue;
    }
function changeValue2(strValue, strLength, countId) {
document.getElementById("site_label_final").innerHTML=strValue;
    }
function changeValue_gen(strValue, strLength, countId) {
document.getElementById("lead_generation_final").innerHTML=strValue;
    }
function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function changeValue3(strValue, strLength, countId) {


document.getElementById("site_phone_final").innerHTML=strValue;

document.getElementById('site_phone_final_hrf').href="tel:"+strValue;

    }

function changeValue4(strValue, strLength, countId)
{
	document.getElementById("site_headline_final").innerHTML=strValue;
}

function changeValue5(strValue, strLength, countId)
{
	document.getElementById("site_headline_final").innerHTML=strValue;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   }

function check()
{
//alert("test");
	if(document.tcp_test.page_name.value=="")
	{
		document.getElementById('text_err').innerHTML="please enter landing page name";
		document.tcp_test.page_name.focus();
		return false;
	}

	if(document.tcp_test.site_title.value=="Title")
	{
		document.getElementById('text_err').innerHTML="please enter site title name";
		document.tcp_test.site_title.value="";
		document.tcp_test.site_title.focus();
		return false;
	}

	/* if(document.tcp_test.site_label.value=="Call")
	{
		document.getElementById('text_err').innerHTML="please enter label";
		document.tcp_test.site_label.value="";
		document.tcp_test.site_label.focus();
		return false;
	} */

	/* if(document.tcp_test.site_phone.value=="4155551212")
	{
		document.getElementById('text_err').innerHTML="please enter Phone number";
		document.tcp_test.site_phone.value="";
		document.tcp_test.site_phone.focus();
		return false;
	} */

	/* if(document.tcp_test.site_phone.value!="")
		{
			if (!IsNumeric(document.tcp_test.site_phone.value)) 
   			{
				document.getElementById('text_err').innerHTML="please enter only integer number";
				document.tcp_test.site_phone.value="";
				document.tcp_test.site_phone.focus();
				return false;
			}
		} */

	if(document.tcp_test.site_headline.value=="Headline")
	{
		document.getElementById('text_err').innerHTML="please enter Headline";
		document.tcp_test.site_headline.value="";
		document.tcp_test.site_headline.focus();
		return false;
	}

	return true;
}

</script>

<script language="JavaScript">
function ajaximage(path)
{
alert("test");
alert(path);
	if (path == '')
	{ 
		document.getElementById("sltOnChange").innerHTML="";
		return;
	}
	 xmlHttp1=GetXmlHttpObject1()
	if (xmlHttp1==null)
 	 {
		alert ("Your browser does not support AJAX!");
		return;
  	} 
	else
	{
		var url="image_upload.php";
		url =url+"?path="+path;
		xmlHttp1.open("GET",url,true);
		xmlHttp1.onreadystatechange=stateChanged1;
		xmlHttp1.send(null);
	}
}
function stateChanged1() 
{ 
	if (xmlHttp1.readyState==4)
	{ 
		document.getElementById("sltGeneral").style.display="None";
		document.getElementById("sltOnChange").innerHTML=xmlHttp1.responseText;
		
	}
}

function GetXmlHttpObject1()
{
var xmlHttp1=null;
try
  {
  xmlHttp1=new XMLHttpRequest();
  }
catch (e)
  {
  try
    {
    xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp1;
}
</script>


<table width="90%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top" align="center"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="20%" valign="top"><?php include("left_pannel.php"); ?></td>
					 <td width="15px">&nbsp;</td>
                    <td valign="top">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                          <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                          <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                        </tr>
                      </table></td>
                  </tr>
                  <tr>
                    <td class="PinkTwosideBorder BoxContent" valign="top">
					<form name="tcp_test" method="POST" action="" onsubmit="return check();" enctype="multipart/form-data">
						<input type="hidden" name="mode" value="save_landing_page">
						<table align="center" width="100%" cellspacing="0" cellpadding="0" >
							<tr>
								<td align="left" valign="top" >
									<table width="100%" border="0" cellspacing="0" cellpadding="0"  >
										<tr>
											<td>
												<table width="100%" border="0" cellspacing="0" cellpadding="0" >
				
				<?php
				if($GLOBALS['msg']!="")
				{
				?>
				<tr>
				<td width="29">&nbsp;</td>
				<td class="font-12 black advertise_tableTxt" align="center">
				<?php
				echo $GLOBALS['msg'];
				?>
				</td>
                </tr>
				<?php
				}
				if($GLOBALS['msg1']!="")
				{
				?>
				<tr>
				<td width="29">&nbsp;</td>
				<td class="font-12 black advertise_tableTxt" align="center">

				<?php
				echo $GLOBALS['msg1'];
				?>
				</td>
                </tr>

				<?php
				}
				if($GLOBALS['msg2']!="")
				{
				?>

				<tr>
				<td width="29">&nbsp;</td>
				<td class="font-12 black advertise_tableTxt" align="center"><strong>URL: http://www.esolz.org/admobweb_new/landing_page_lead_gen.php?id=<?php echo $GLOBALS['msg2'];?></strong></td>
                </tr>
				
				<?php
				}
				if($GLOBALS['msg2']!="")
				{
				?>

				<tr>
				<td width="29">&nbsp;</td>
				<td class="font-12 black advertise_tableTxt" align="center"><a href="create_landing_page.php">Back</a></td>
                </tr>
				
				<?php
				}
				?>

               <tr>
				<td width="29"><img src="images/TitleArrowLeft.jpg" alt="" width="29" height="30"></td>
				<td class="MarketTitleBg">Landing Page Builder</td>
                </tr>


                </table>
		  </td>
          </tr>
		<tr><TD align="center">

		<table width="98%" border="0" cellspacing="0" cellpadding="0" >
                              <tr>
                                
                                <td valign="top"><table border="0" cellspacing="0" cellpadding="0">
									
									<?php
									if($GLOBALS['msg2']!="")
				{
				?>
									<tr>
                                    <td height="30" colspan="5" align="center" style="padding-top:20px;padding-bottom:20px;" id="text_err"><?php echo $GLOBALS['msg'];?></td>
                                  </tr>
									<?php
										}
									?>

									<tr>
                                    <td height="30" colspan="5" align="center" style="padding-top:20px;padding-bottom:20px;" class="ERR"><font id="text_err"></font></td>
                                  </tr>

									 <tr>
                                    <td width="100" height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                                        <td class="FormNameBoxBg" nowrap="true">Landing Page Name:</td>
                                        <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                                      </tr>
                                    </table></td>
                                    <td width="14">&nbsp;</td>
                                    <td><input name="page_name" type="text" class="InputBox" id="page_name" value="<?php echo $rec['pageName'];?>"></td>
                                    <td width="11">&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>


                                  <tr>
                                    <td width="100" height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                                        <td class="FormNameBoxBg">Site Title Name:</td>
                                        <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                                      </tr>
                                    </table></td>
                                    <td width="14">&nbsp;</td>
                                    <td><input name="site_title" type="text" class="InputBox" id="site_title" onchange="isChanged=true;" onkeyup="javascript:changeValue1(this.value, 255, 'site_title_count');" value="
									<?php
									if($rec['pageTitle']!="")
									{
									 	echo $rec['pageTitle'];
									}
									else
									{
										echo "Title";
									}
									?>
									"></td>
                                    <td width="11">&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>
	
								<tr>
                                    <td width="100" height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                                        <td class="FormNameBoxBg">Image:</td>
                                        <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                                      </tr>
                                    </table></td>
                                    <td width="14">&nbsp;</td>
                                    <td>
<!--------------------------------------------------------------------------------------->

<div id="iframe_container" >
		<iframe src="advertise_photo.php" frameborder="0" scrolling="No" id="iframid" height="50" class="radiotxt" ></iframe>
	</div>
	<span id="imageFileError" style="display:none; color:#FF0000; font-size:12px; font-weight:bold;" class="nametxt"></span>
<input type="hidden" name="PhotoSelectValue" id="PhotoSelectValue" value="" />
	<input type="hidden" name="imagefileHIDDEn" id="imagefileHIDDEn" value="<?php if($_SESSION['ADD_imagefileHIDDEn'] != '') echo $_SESSION['ADD_imagefileHIDDEn']; ?>" /></div>

<!------------------------------------------------------------------------------->

<!--<input type="file" id="front_image" name="front_image" class="InputBox"  >&nbsp;<input name="" type="button" value="Build" onClick="ajaximage(document.getElementById('front_image').value);" />--></td>
                                    <td width="11">&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>

								 <!--<tr>
                                    <td width="100" height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                                        <td class="FormNameBoxBg">Label:</td>
                                        <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                                      </tr>
                                    </table></td>
                                    <td width="14">&nbsp;</td>
                                    <td><input name="site_label" type="text" class="InputBox" id="site_label" onchange="isChanged=true;" onkeyup="javascript:changeValue2(this.value, 255, 'site_label_count');" value="
									<?php
									if($rec['label']!="")
									{
									 	echo $rec['label'];
									}
									else
									{
										echo "Call";
									}
									?>
										">

									<input type="hidden" name="input1">
					<a href="javascript:TCP.popup(document.forms['tcp_test'].elements['input1'])">
					<img style="cursor: pointer; padding-left: 3px;" src="images/palette.gif" alt="Palette">
					</a>

									</td>
                                    <td width="11">&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>-->
	
									
									<!--<tr>
                                    <td width="100" height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                                        <td class="FormNameBoxBg">Phone Number:</td>
                                        <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                                      </tr>
                                    </table></td>
                                    <td width="14">&nbsp;</td>
                                    <td class="font-12 black advertise_tableTxt" nowrap="true"><input name="site_phone" type="text" class="InputBox" id="site_phone" onchange="isChanged=true;" onkeyup="javascript:changeValue3(this.value, 255, 'site_phone_count');" value="
									<?php
									if($rec['phoneNo']!="")
									{
									 	echo $rec['phoneNo'];
									}
									else
									{
										echo "4155551212";
									}
									?>
">&nbsp;(Example: 4155551212)
										
									</td>
                                    <td width="11">&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>-->

								<tr>
                                    <td width="100" height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                                        <td class="FormNameBoxBg">Headline:</td>
                                        <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                                      </tr>
                                    </table></td>
                                    <td width="14">&nbsp;</td>
                                    <td><input name="site_headline" type="text" class="InputBox" id="site_headline" onchange="isChanged=true;" onkeyup="javascript:changeValue4(this.value, 255, 'site_headline_count');" value="
									<?php
									if($rec['headline']!="")
									{
									 	echo $rec['headline'];
									}
									else
									{
										echo "Headline";
									}
									?>
									">

									<input type="hidden" name="input0">
	<a href="javascript:TCP.popup(document.forms['tcp_test'].elements['input0'])">
    <img style="cursor: pointer; padding-left: 3px;" src="images/palette.gif" alt="Palette">
	</a>
	
									</td>
                                    <td width="11">&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>


                                  <tr>
                                    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                                        <td class="FormNameBoxBg" nowrap="true">Page Text:</td>
                                        <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                                      </tr>
                                    </table></td>
                                    <td>&nbsp;</td>
                                    <td valign="middle" class="font-12 black advertise_tableTxt" nowrap="true">

									<textarea id="description" name="description" class="InputtextArea" cols="42" rows="5" onchange="isChanged=true;" onkeyup="javascript:changeValue(this.value, 255, 'descriptionCount');">
<?php
									if($rec['details']!="")
									{
									 	echo $rec['details'];
									}
									else
									{
										echo "My page text.";
									}
									?>
</textarea>
	
									<!--<textarea name="textarea" id="textarea" cols="45" rows="5" class="InputtextArea"></textarea>-->
									<font class="BlackContent">(Characters left:</font><span id="descriptionCount">255</span><font class="BlackContent"> )</font>			
									</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>

								<tr>
                                    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                                        <td class="FormNameBoxBg" nowrap="true">Lead Generation:</td>
                                        <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                                      </tr>
                                    </table></td>
                                    <td>&nbsp;</td>
                                    <td valign="middle" class="font-12 black advertise_tableTxt">
									
									<textarea id="lead_generation" name="lead_generation" class="InputtextArea" cols="42" rows="5" onchange="isChanged=true;" onkeyup="javascript:changeValue_gen(this.value, 255, 'lead_generation');">
<?php
									if($rec['lead_generation']!="")
									{
									 	echo $rec['lead_generation'];
									}
									else
									{
										echo "My page text.";
									}
									?>
</textarea>
	
										
									</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>


                                  <tr>
                                    <td height="30">&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td align="left" valign="bottom"><input name="button3" type="submit" class="SubmitInputButton" id="button3" value="Submit">&nbsp;
									<input name="button3" type="button" class="SubmitInputButton" id="button3" value="Cancel" onclick="javascript: window.location='create_landing_page.php';">
									</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                  </tr>
                                  
                                </table></td>
								<td valign="top" style="padding-top:20;">
								<table width="100%" cellspacing="0" cellpadding="0" style="border:1px;">
		
                                      <tr>
										<td>
											<table width="100%" cellspacing="0" cellpadding="0" border="1">
								
											<tr>
											<td align="center">
											<table width="100%" cellspacing="0" cellpadding="0" border="0">

											<tr>
										<td bgcolor="Silver">
											<div id="site_title_show"><?php
									if($rec['pageName']!="")
									{
									 	echo $rec['pageName'];
									}
									else
									{
										echo "Title";
									}
									?></div>
										</td>
									  </tr>

																			
<!--------------------------------------------------------------------------------->

											<tr><TD align="center" style="padding-top:10px;"><div id="images_container" style="width:260px;" class="radiotxt">&nbsp;<br/>
										<?php if($_SESSION['ADD_imagefileHIDDEn'] != ''){?><img src="advertise_thumb/<?php echo $_SESSION['ADD_imagefileHIDDEn']; ?>"><?php } ?>
										</div></TD></tr>

<!------------------------------------------------------------------------------------>



											<!-- <tr>
												<td align="center">
													<span id="site_label_final"><?php
									if($rec['label']!="")
									{
									 	echo $rec['label'];
									}
									else
									{
										echo "Call";
									}
									?></span>
													<a href="tel:4155551212" id="site_phone_final_hrf">
													<span id="site_phone_final"><?php
									if($rec['phoneNo']!="")
									{
									 	echo $rec['phoneNo'];
									}
									else
									{
										echo "4155551212";
									}
									?></span>
													</a>			
												</td>
											</tr> -->

											<tr>
												<td align="center">
													<span id="site_headline_final"><strong><?php
									if($rec['headline']!="")
									{
									 	echo $rec['headline'];
									}
									else
									{
										echo "Headline";
									}
									?></strong></span>
												</td>
											</tr>

											<tr>
												<td align="center" style="padding-top:10px;">
													<span id="description_final"><?php
									if($rec['details']!="")
									{
									 	echo $rec['details'];
									}
									else
									{
										echo "My page text.";
									}
									?></span>
												</td>
											</tr>

									<tr>
												<td align="center" style="padding-top:10px;padding-bottom:10px;">
													<span id="lead_generation_final"><?php
									if($rec['lead_generation']!="")
									{
									 	echo $rec['lead_generation'];
									}
									else
									{
										echo "Enter your info below.";
									}
									?></span>
												</td>
											</tr>

										<tr><TD align="center"><input type="text" name="value_code" disabled="disabled"></TD></tr>
	
										<tr><TD align="center" style="padding-top:5px;"><input type="submit" name="value_code" disabled="disabled" value="submit"></TD></tr>


											</table>
											</td>
											</tr>
											</table>
										</td>
									  </tr>
								</table>
								</td>
                              </tr>
                            </table>

		</TD></tr>
		</table>

    </td>
  </tr>

</table></form></td>
                  </tr>
                  <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                          <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                          <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                        </tr>
                      </table></td>
                  </tr>
                </table></td>
                   
                    </tr>
                </table></td>
              </tr>
            </table>


<?php
}
function save_landing_page()
{

if($_REQUEST['id']=="")
{


  $query="insert into adspace_landing_page set
		UserId='".$_SESSION['siteuserId']."' , 
		pageName='".$_POST['page_name']."',
		pageTitle='".$_POST['site_title']."',
		images='".$_POST['imagefileHIDDEn']."',
		headline='".$_POST['site_headline']."',
		headlineStyle='".$_POST['input0']."',
		details='".$_POST['description']."',
		lead_generation='".$_POST['lead_generation']."',
		type='lead_generation',
		created_date=NOW()
		";
mysql_query($query)or die(mysql_error());
$id=mysql_insert_id();


$GLOBALS['msg']="Landing page created successfully.";
$GLOBALS['msg1']="Your landing page url is";
$GLOBALS['msg2']="$id";

$landing_url='http://www.esolz.org/admobweb_new/landing_page_lead_gen.php?id='.$id;

$update_url="update adspace_landing_page set landing_url = '".$landing_url."' where landingId = '".$id."'";
mysql_query($update_url);
}
else
{

	 $query="update adspace_landing_page set
		UserId='".$_SESSION['siteuserId']."' , 
		pageName='".$_POST['page_name']."',
		pageTitle='".$_POST['site_title']."',
		images='".$_POST['imagefileHIDDEn']."',
		headline='".$_POST['site_headline']."',
		headlineStyle='".$_POST['input0']."',
		details='".$_POST['description']."',
		lead_generation='".$_POST['lead_generation']."',
		type='Click-2-Call' where landingId='".$_REQUEST['id']."'
		";
mysql_query($query);
$GLOBALS['msg']="Landing page updated successfully.";
$GLOBALS['msg1']="Your landing page url is";
$GLOBALS['msg2']="$_REQUEST[id]";

}

main_content("main();");

}
?>
